{% extends 'layout/body.html' %}
{% block title %}
    班级管理
{% endblock %}
{% block content %}
    {{ abc }}
    <div class="row mt-2">
        <div class="col-12 text-right pr-5">
            <a class="btn btn-primary" href="{{ url_for('clazz.add') }}"><i class="bi bi-plus-lg"></i>新增</a>
        </div>
        <div class="col-6 offset-3">
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>名称</th>
                    <th>班级人数</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody>
                {% for clazz in clazzes %}
                    <tr>
                        <td>{{ loop.index }}</td>
                        <td>{{ clazz.name }}</td>
                        <td>{{ clazz.students_count }}</td>
                        <td class="text-right">
                            <a href="{{ url_for('clazz.edit', id=clazz.id) }}"><i class="bi bi-pencil-fill"></i></a>
                            <a onclick="onDelete(event)" href="{{ url_for('clazz.delete', id=clazz.id) }}"><i class="text-danger bi bi-trash"></i></a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    <script>
        function onDelete(event) {
            event.preventDefault();
            if (confirm("该操作不可逆，请谨慎操作")) {
                window.location.href = event.currentTarget.href;
            }
        }
    </script>
{% endblock %}
